<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" name="" id="">
    <button>获取github用户列表数据</button>
    <ul>

    </ul>
    <script>
        // https://api.github.com/search/users?q=y
        let oInput = document.querySelector('input');
        let oBtn = document.querySelector('button');
        let oUl = document.querySelector('ul');
        
        oBtn.onclick = function(){
            let keyword = oInput.value;
            const xhr = new XMLHttpRequest();
            xhr.open('get', 'https://api.github.com/search/users?q=' + keyword);
            xhr.responseType = 'json';
            xhr.send();
            xhr.onreadystatechange = function(){
                if(xhr.readyState === 4){
                    if(xhr.status >= 200 && xhr.status < 300){
                        // console.log(xhr.response,typeof xhr.response);
                        let {items} = xhr.response;
                        let str = '';
                        items.forEach(user=>{
                            str += `
                                <li>
                                    <p>${user.login}</p>
                                    <div>
                                        <img  src="${user.avatar_url}"/>
                                    </div>
                                </li>
                            `
                        })
                        oUl.innerHTML = str;
                    }
                }
            }
        }
    </script>
</body>
</html>